import server from '@/utils/server'
import ServerConstants from '@/utils/ServerConstants'

/*获取首页加载数据*/
export function homePage (params, success, errorfun) {
  if (server._isEmpty(params)) {
    params = {}
  }
  return new Promise((resolve, reject) => {
    server.getJSON(ServerConstants.REQ_GET_GOODS_INDEX, params,
      function (response) {
        resolve(response.data)
        server.call(success, response)
      }, function (error) {
        server.call(errorfun, error)
        reject(error)
      })
  })
}

/*获取首页分类*/
export function getCatagory(params, success, errorfun) {
  if (server._isEmpty(params)) {
    params = {}
  }
  return new Promise((resolve, reject) => {
    server.getJSON(ServerConstants.REQ_GET_CATAGORY_HOME, params,
      function (response) {
        resolve(response.data)
        server.call(success, response)
      }, function (error) {
        server.call(errorfun, error)
        reject(error)
      })
  })
}

/*获取首页banner*/
export function getbanner(params, success, errorfun) {
  if (server._isEmpty(params)) {
    params = {}
  }
  return new Promise((resolve, reject) => {
    server.getJSON(ServerConstants.REQ_GET_BANNER, params,
      function (response) {
        resolve(response.data)
        server.call(success, response)
      }, function (error) {
        server.call(errorfun, error)
        reject(error)
      })
  })
}


